﻿using SocialApi.Core.Extensions;

namespace SocialApi.Instagram.Entities.Methods.Users
{
    internal class CountMethod : ICounts
    {
        #region Члены ICounts

        /// <summary>
        /// Загруженные медиа данные
        /// </summary>
        public int Media { get; private set; }

        /// <summary>
        /// Понравилось ?
        /// </summary>
        public int Follows { get; private set; }

        /// <summary>
        /// Добавлены ?
        /// </summary>
        public int FollowedBy { get; private set; }

        #endregion

        internal static CountMethod This { get; private set; }

        public CountMethod()
        {
            This = this;
        }

        internal ICounts SetData(ICounts counts)
        {
            var properties = counts.GetType().GetProperties();
            foreach (var propertyInfo in properties)
            {
                switch (propertyInfo.Name)
                {
#if NET_4_5
                    case "Media":
                        Media = propertyInfo.GetValue(counts).ConvertTo<int>();
                        break;
                    case "Follows":
                        Follows = propertyInfo.GetValue(counts).ConvertTo<int>();
                        break;
                    case "FollowedBy":
                        FollowedBy = propertyInfo.GetValue(counts).ConvertTo<int>();
                        break;
#else
                    case "Media":
                        Media = propertyInfo.GetValue(counts, null).ConvertTo<int>();
                        break;
                    case "Follows":
                        Follows = propertyInfo.GetValue(counts, null).ConvertTo<int>();
                        break;
                    case "FollowedBy":
                        FollowedBy = propertyInfo.GetValue(counts, null).ConvertTo<int>();
                        break;
#endif
                }
            }
            return this;
        }
    }
}